return “Birds produce offsprings by laying eggs and
hatching them”;
}
}
contract SpecialAnimal is Mammal, Bird {
function specialFunction() public view returns(string
memory) {
this.mammalFunction();
this.birdFunction();
return “Special Animal can Birds produce offsprings by
laying eggs and hatching them. Theie females have mammary
glands “;
}
}
2.5.20.4 Polymorphism
Polymorphism is a feature, by which we can perform a single action
in different ways. In Solidity, we can perform polymorphism by
function overloading, by using the same virtual keyword in the
parent contract and the override keyword in the child contract.
Here, when we run the Mammal contract and then run
mammalFunction, the output would be “Mammals produce offspring
by directly giving birth and females have mammary glands”;
however, if we deploy and run the SpecialMammal contract, the
output of the function mammalFunction would be “Humans are
special mammals who can speak and walk with two legs”.
The following is an example of function overloading when a function
with the same name can be used multiple times and each has a
different set of input parameters:
// SPDX-License-Identifier: SOME IDENTIFIER
pragma solidity ^0.8.10;
contract Calculator {
function calculate(uint a, uint b) public pure returns(uint)
{